<template>
  <div>
    <el-container>
      <el-form
        label-position="right"
        ref="form"
        :model="form"
        label-width="100px"
      >
       <el-row v-for="(subModule, index) in subModuleList" :key="subModule">{{ subModule }}:
          <el-checkbox-group v-if="index==0" v-model="form.defining_feature">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
           <el-checkbox-group v-if="index == 1" v-model="form.risk_group">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 2" v-model="form.risk_factor">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 3" v-model="form.relevant_factor">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
          <el-checkbox-group v-if="index == 4" v-model="form.evidence">
            <el-col :span="4" v-for="item in subModuleItemList[index]" :key="item">
              <el-checkbox :label="item">{{ item }}</el-checkbox>
            </el-col>
          </el-checkbox-group>
        </el-row>
        
      </el-form>
    </el-container>
  </div>
</template>

<script>
var BaaS = require("minapp-sdk");
let clientID = "9ed0a3da89683e42d793";
BaaS.init(clientID);

export default {
  name: "healthBehavior",
  props: {
    module_healthBehavior: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      subModuleList: [    
        "定义性特征",
        "危险人群",
        "危险因素",
        "相关因素",
        "循证知识"
    ],
      subModuleListSet: new Set(),
      subModuleItemList: [
        [
            "表达加强个人发展独立的意愿",
            "表达加强管理疾病的意愿",
            "表达加强管理危险因素的意愿",
            "表达加强管理医嘱方案的意愿",
            "表达加强管理症状的意愿",
            "表达加强健康独立的意愿",
            "表达加强免疫/接种状态的意愿",
            "表达加强生活独立的意愿",
            "表达加强幸福独立的意愿",
            "表达加强选择日常生活以达到目标的意愿",
            "表达加强学习的意愿",
            "表达加强自理策略知识的意愿",
            "表达加强自理的意愿",
            "不卫生的环境",
            "从事危险的行为",
            "对他人的破坏行为",
            "对自己的破坏行为",
            "废品暴露对肺的影响",
            "废品暴露对肝脏的影响",
            "废品暴露对皮肤的影响",
            "废品暴露对胃肠道的影响",
            "辐射暴露对免疫系统的影响",
            "辐射暴露对神经系统的影响",
            "辐射暴露对遗传的影响",
            "辐射暴露对肿瘤的影响",
            "沟通方式改变",
            "化学物质暴露对肺的影响",
            "化学物质暴露对免疫系统的影响",
            "化学物质暴露对皮肤的影响",
            "化学物质暴露对神经系统的影响",
            "化学物质暴露对肾的影响",
            "化学物质暴露对胃肠道的影响",
            "患病频繁",
            "家庭责任过多",
            "健康状态改变最小化",
            "拒绝接受健康状况的改变",
            "母乳喂养时间延长",
            "难以维持舒适的环境",
            "缺乏炊具",
            "缺乏获得社会支持的途径",
            "缺乏家庭日用织品",
            "缺乏解决问题的方法",
            "缺乏目标导向的行为",
            "缺乏维持家庭的设备",
            "乳头刺激性乳汁分泌不足",
            "乳汁分泌低于婴儿需要量",
            "乳汁分泌延迟",
            "杀虫剂暴露对肺的影响",
            "杀虫剂暴露对皮肤的影响",
            "杀虫剂暴露对神经系统的影响",
            "杀虫剂暴露对肾的影响",
            "杀虫剂暴露对胃肠道的影响",
            "生物性因素暴露对肺的影响",
            "生物性因素暴露对皮肤的影响",
            "生物性因素暴露对神经系统的影响",
            "生物性因素暴露对肾的影响",
            "生物性因素暴露对胃肠道的影响",
            "维持家庭的能力受损",
            "未能采取预防健康问题的行为",
            "污染暴露对肺的影响",
            "污染暴露对神经系统的影响",
            "无法关注信息",
            "无法满足基本需求",
            "无法满足角色期望",
            "无法寻求帮助",
            "无法应对环境",
            "吸烟",
            "需要帮助维持家庭",
            "衣着过少",
            "因不卫生的条件引起的感染类型",
            "因不卫生的条件引起的疾病类型",
            "婴儿便秘",
            "婴儿拒绝吸吮乳头",
            "婴儿排出少量浓缩尿",
            "婴儿频繁啼哭",
            "婴儿频繁寻求吸吮乳头",
            "婴儿体重每月增加<500g",
            "组织信息困难"
        ],
        [
            "成熟危机",
            "大气污染物暴露",
            "儿童＜5岁",
            "辐射暴露",
            "高污染地区暴露",
            "既往污染物暴露",
            "经济危机",
            "酒精滥用家族史",
            "老年人",
            "摄入污染的物质",
            "生物恐怖活动暴露",
            "育龄期暴露",
            "灾难于暴露"
        ],
        [
            "不合理的使用个人防护设备",
            "从社会关系中分离",
            "倒班",
            "防护服不足",
            "非健康消极习惯的不安全行为",
            "过分自信的不安全行为",
            "化学因素暴露",
            "极端温度暴露",
            "角色扮演不良",
            "劳动关系",
            "躯体工作负担",
            "缺乏个人防护设备",
            "生物因素暴露",
            "时间管理不良",
            "物理环境不良",
            "误解信息",
            "心理困扰",
            "夜班倒白班",
            "噪音暴露",
            "震动暴露",
            "职业倦怠",
            "致畸剂暴露"
        ],
        [
            "榜样不良",
            "不准确的威胁评估",
            "对应对环境的能力信心不足",
            "防护服使用不当",
            "非保护性暴露于辐射物",
            "非保护性暴露于化学物质",
            "非保护性暴露于重金属",
            "高度威胁",
            "个人卫生行为不良",
            "共存性暴露",
            "家庭计划不足",
            "家庭卫生行为不良",
            "家庭组织不良",
            "紧张缓解策略无效",
            "母亲的治疗方案",
            "母亲体液容量不足",
            "母亲吸烟",
            "母亲饮酒",
            "母亲营养不良",
            "年幼儿童出现剥落脱皮",
            "铺有地毯的地板",
            "缺乏邻居资源的知识",
            "缺乏维持家庭的知识",
            "食物受到化学性污染",
            "市政服务不良",
            "水受到化学性污染",
            "污染控制不良",
            "无法保存适应性能量",
            "吸吮反射无效",
            "吸吮乳头的机会不足",
            "吸吮乳头的时间不足",
            "衔接乳头无效",
            "抑制泌乳",
            "在家中使用与环境相关的污染物",
            "在缺乏有效保护的情况下使用毒性物质",
            "在使用与环境相关的污染物的地方玩耍",
            "在通风不良的地方使用毒性物质",
            "准备应对压力源的机会不足"
        ],
        [
            "宿疾"
        ]
      ],
      submoduleItemListSet: new Set(),
      form: {
        defining_feature: [],
        risk_group: [],
        risk_factor: [],
        relevant_factor: [],
        evidence: [],
      },
      formRules: {},
    };
  },
  methods: {
    getSubModuleItem(index1,index2) {
        let itemSet = new Set();
        // this.subModuleItemList[index2] = []; //将当前数组的元素设置为数组就是二维数组了
        let query = new BaaS.Query();
        let overall_eval = new BaaS.TableObject("overall_eval_item");
        query.compare("module", "=", this.module_healthBehavior);
        query.compare("submodule", "=", this.subModuleList[index2]);
        overall_eval
          .setQuery(query)
          .select(["submodule", "item"])
          .limit(1000)
          .offset(index1)
          .find()
          .then((res) => {
            let datas = res.data.objects;
            datas.forEach((data) => {
              itemSet.add(data.item);
            });
            if (res.data.meta.next !== null) {
              this.getSubModuleItem(index1 + 1000,index2);
            } else {
              this.subModuleItemList.push(Array.from(itemSet));
            //   console.log(this.subModuleItemList[index2]);
            }
          });
    },
    getSubModule(index) {
      let query = new BaaS.Query();
      let overall_eval = new BaaS.TableObject("overall_eval_item");
      query.compare("module", "=", this.module_healthBehavior);
      overall_eval
        .setQuery(query)
        .select(["module", "submodule"])
        .limit(1000)
        .offset(index)
        .find()
        .then((res) => {
          let datas = res.data.objects;
          datas.forEach((data) => {
            this.subModuleListSet.add(data.submodule);
          });
          if (res.data.meta.next !== null) {
            this.getSubModule(index + 1000);
          } else {
            this.subModuleList = Array.from(this.subModuleListSet);
            console.log(this.subModuleList);
            for (let i = 0; i < this.subModuleList.length; i++) {
                this.getSubModuleItem(0,i);
            }  
            console.log(this.subModuleItemList); 
          }
        });
        
    },
    init() {
      this.getSubModule(0);
    },
  },
  mounted() {
    // this.init();
  },
};
</script>

<style>
</style>